package br.trainee.web.constraint.impl;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import br.trainee.web.constraint.service.Cnpj;

public class CnpjImpl implements ConstraintValidator<Cnpj, String>{
	
	private String mensagem;
	
	@Override
	public void initialize(Cnpj anotacao) {
		this.mensagem = anotacao.message(); 
	}

	@Override
	public boolean isValid(String valor, ConstraintValidatorContext context) {
			
			if(!valor.matches("[0-9]{2}\\.?[0-9]{3}\\.?[0-9]{3}\\/?[0-9]{4}\\-?[0-9]{2}")){
				
				return false;
			}
		
		return true;
	}

}
